//
//  OtherTimeFormatCell.swift
//  MoyoungDevice
//
//  Created by 易先生 on 2022/8/17.
//

import UIKit
import MYModule

class OtherTimeFormatCell: TableViewCell {

	override func makeUI() {
		super.makeUI()

		contentView.backgroundColor = UIColor.background

        contentView.addSubview(titleLabel)
        contentView.addSubview(lineView)
        
		contentView.addSubview(descLabel)
		contentView.addSubview(iconImageView)

        lineView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(20)
            make.trailing.equalToSuperview().offset(-20)
            make.height.equalTo(1)
            make.bottom.equalToSuperview()
        }
    
		titleLabel.snp.makeConstraints { make in
			make.top.equalToSuperview().offset(16)
			make.leading.equalToSuperview().offset(20)
			make.bottom.equalToSuperview().offset(-16)
			make.trailing.lessThanOrEqualTo(descLabel.snp.leading).offset(-10)
		}

		iconImageView.snp.makeConstraints { make in
			make.trailing.equalToSuperview().offset(-20)
			make.centerY.equalToSuperview()
		}

		descLabel.snp.makeConstraints { make in
            make.trailing.equalTo(iconImageView.snp.leading).offset(-10)
			make.centerY.equalToSuperview()
		}
	}

	public func bind(to cellModel: OtherTimeFormatCellModel) {
        titleLabel.text = cellModel.title
        cellModel.value.bind(to: descLabel.rx.text).disposed(by: rx.disposeBag)
        
        guard "device_heart_rate_remind_max".language == cellModel.title else {
            lineView.isHidden = false
            return
        }
        lineView.isHidden = true
	}

	private lazy var descLabel: Label = {
		let descLabel = Label()
		descLabel.textColor = UIColor.assist_A9A9A9
		descLabel.numberOfLines = 0
        descLabel.font = Fonts.systemFont(ofSize: 12)
		return descLabel
	}()

	private lazy var iconImageView: ImageView = {
		let iconImageView = ImageView()
		iconImageView.image = UIImage(named: "ic_next_continue")?.setupImageTintColor(tintColor: UIColor.assist_D0D0D0)
		return iconImageView
	}()
    
    public lazy var titleLabel: Label = {
        let titleLabel = Label()
        titleLabel.textColor = UIColor.assist_222222
        titleLabel.numberOfLines = 0
        titleLabel.font = Fonts.systemFont(ofSize: 16)
        return titleLabel
    }()

    public lazy var lineView: View = {
        let lineView = View()
        lineView.backgroundColor = UIColor.assist_D0D0D0
        return lineView
    }()
}
